<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of RSS
 *
 * @author Sabonay
 */
include 'RSSItem.php';

class RSS {
    var $title;
    var $link;
    var $description;
    var $language="en-gb";
    var $copyright;
    var $rssItems =array();
    var $lastBuildDate;

    var $styleSheet;
    var $doc;
    var $ttl;

    var $fileLoc;
    var $managingEditor;
    var $webMaster;

    var $category;
    var $generator;

    var $image=array(
            "title"=>"",
            "url" =>"",
            "link"=>"");

    public function __construct($title,$link,$desc,$copyright) {
        $this->title= $title;
        $this->link =$link;
        $this->description =$desc;
        $this->copyright =$copyright;
    }

    function buildRSS() {

        if(strlen($this->lastBuildDate)<1)
            $this->lastBuildDate = date("D, d M Y H:i:s ")."GMT";

        header("Content-Type: application/xml; charset=ISO-8859-1");
        $stringBuilder= "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
        $stringBuilder.= "<rss version=\"2.0\">\n";
        $stringBuilder.= " <channel>\n";
        $stringBuilder.= "\t<title>".$this->title."</title>\n";
        $stringBuilder.= "\t<link>".$this->link."</link>\n";
        $stringBuilder.= "\t<description>".strip_tags($this->description)."</description>\n";
        $stringBuilder.= "\t<language>".$this->language."</language>\n";
        $stringBuilder.= "\t<copyright>".$this->copyright."</copyright>\n";
        if(strlen($this->image["url"])>1){
            $stringBuilder.="<image>
                                <title>".$this->image["title"]."</title>
                                <url>".$this->image["url"]."</url>";
            if(strlen($this->image["link"])>1){
                $stringBuilder.="<link>".$this->image["link"]."</link>";
            }
         $stringBuilder.="</image>";
        }
        if(strlen($this->managingEditor)>1)
            $stringBuilder.= "\t<managingEditor>".$this->managingEditor."</managingEditor>\n";

        if(strlen($this->webMaster)>1)
            $stringBuilder.= "\t<webMaster>".$this->webMaster."</webMaster>\n";

        $stringBuilder.= "\t<lastBuildDate>".$this->lastBuildDate."</lastBuildDate>\n";

        if(strlen($this->category)>1)
            $stringBuilder.= "\t<category>".$this->category."</category>\n";

        if(strlen($this->generator)>1)
            $stringBuilder.= "\t<generator>".$this->generator."</generator>\n";

        $stringBuilder.= $this->loadRSSItems();

        $stringBuilder.=" </channel>\n</rss>";
        if(strlen($this->fileLoc)>0) {
        }
        echo $stringBuilder;
    }

    function loadRSSItems() {
        $item="";
        $rssItem  = "";

        for($i=0;$i<count($this->rssItems);$i++) {
            $rssItem = $this->rssItems[$i];//["title"],$this->rssItems[$i]['description'],$this->rssItems[$i]['link'],$this->rssItems[$i]['pubdate']);
            $item.= $rssItem->buildRssItem();
        }

        return $item;
    }

}


?>